using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Data.Linq;
using System.Collections;


namespace BHXH.LinqRepository
{
    public class ChiTietPhieuRepository : Repository<ChiTietPhieu>
    {
        public ChiTietPhieu GetByPhieuID_MaCau(Guid phieuID, int maCau)
        {
            return dataContext.ChiTietPhieus.Where(c => c.PhieuID == phieuID && c.MaCau == maCau).FirstOrDefault();
        }
        public void InsertOne(ChiTietPhieu one)
        {
            one.ID = Guid.NewGuid();
            Add(one);
            //dataContext.ChiTietPhieus.InsertOnSubmit(one);
            dataContext.SubmitChanges();
        }
        public void EditOne(ChiTietPhieu one)
        {
            //dataContext.ChiTietPhieus.Attach(one, true);
            //Update(one);
            dataContext.SubmitChanges();
        }
        public void DeleteAllByPhieuId(Guid phieuId)
        {
            var obj = dataContext.ChiTietPhieus.Where(c => c.PhieuID == phieuId).ToList();
            dataContext.ChiTietPhieus.DeleteAllOnSubmit(obj);
        }

        public List<int[]> Dem2TieuChiCungMotPhieu_KieuEquals(string loaiPhieu, int soHang, int soCot, int maCauHang, int maCauCot)
        {
            List<ChiTietPhieu> lsChiTietPhieuMaCauHang = (from ds in dataContext.Phieus
                                                          join ct in dataContext.ChiTietPhieus
                                                              on ds.ID equals ct.PhieuID
                                                          where ct.MaCau == maCauHang && ds.LoaiPhieu == loaiPhieu && ct.CauTraLoiFIX1 != ""
                                                          select ct).ToList();
            List<System.Guid> lsHang1ID = new List<Guid>();
            List<System.Guid> lsHang2ID = new List<Guid>();
            List<System.Guid> lsHang3ID = new List<Guid>();
            List<System.Guid> lsHang4ID = new List<Guid>();
            List<System.Guid> lsHang5ID = new List<Guid>();
            List<System.Guid> lsHang6ID = new List<Guid>();
            List<System.Guid> lsHang7ID = new List<Guid>();
            List<System.Guid> lsHang8ID = new List<Guid>();
            if (soHang >= 1)
                lsHang1ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "1" select ds.PhieuID).ToList();
            if (soHang >= 2)
                lsHang2ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "2" select ds.PhieuID).ToList();
            if (soHang >= 3)
                lsHang3ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "3" select ds.PhieuID).ToList();
            if (soHang >= 4)
                lsHang4ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "4" select ds.PhieuID).ToList();
            if (soHang >= 5)
                lsHang5ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "5" select ds.PhieuID).ToList();
            if (soHang >= 6)
                lsHang6ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "6" select ds.PhieuID).ToList();
            if (soHang >= 7)
                lsHang7ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "7" select ds.PhieuID).ToList();
            if (soHang >= 8)
                lsHang8ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "8" select ds.PhieuID).ToList();


            List<ChiTietPhieu> lsChiTietPhieuMaCauCot = (from ds in dataContext.Phieus
                                                         join ct in dataContext.ChiTietPhieus
                                                             on ds.ID equals ct.PhieuID
                                                         where ct.MaCau == maCauCot && ds.LoaiPhieu == loaiPhieu && ct.CauTraLoiFIX1 != ""
                                                         select ct).ToList();
            //Tạo biến temp để developer xem số lượng câu query được
            int count = lsChiTietPhieuMaCauHang.Count;
            int count2 = lsChiTietPhieuMaCauCot.Count;

            int number1_Hang1 = 0, number2_Hang1 = 0, number3_Hang1 = 0, number4_Hang1 = 0, number5_Hang1 = 0, number6_Hang1 = 0;
            int number1_Hang2 = 0, number2_Hang2 = 0, number3_Hang2 = 0, number4_Hang2 = 0, number5_Hang2 = 0, number6_Hang2 = 0;
            int number1_Hang3 = 0, number2_Hang3 = 0, number3_Hang3 = 0, number4_Hang3 = 0, number5_Hang3 = 0, number6_Hang3 = 0;
            int number1_Hang4 = 0, number2_Hang4 = 0, number3_Hang4 = 0, number4_Hang4 = 0, number5_Hang4 = 0, number6_Hang4 = 0;
            int number1_Hang5 = 0, number2_Hang5 = 0, number3_Hang5 = 0, number4_Hang5 = 0, number5_Hang5 = 0, number6_Hang5 = 0;
            int number1_Hang6 = 0, number2_Hang6 = 0, number3_Hang6 = 0, number4_Hang6 = 0, number5_Hang6 = 0, number6_Hang6 = 0;
            int number1_Hang7 = 0, number2_Hang7 = 0, number3_Hang7 = 0, number4_Hang7 = 0, number5_Hang7 = 0, number6_Hang7 = 0;
            int number1_Hang8 = 0, number2_Hang8 = 0, number3_Hang8 = 0, number4_Hang8 = 0, number5_Hang8 = 0, number6_Hang8 = 0;

            if (lsHang1ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang2ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang3ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang4ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang5ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang6ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang7ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            if (lsHang8ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "1").Count();
                if (soCot >= 2)
                    number2_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "2").Count();
                if (soCot >= 3)
                    number3_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "3").Count();
                if (soCot >= 4)
                    number4_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "4").Count();
                if (soCot >= 5)
                    number5_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "5").Count();
                if (soCot >= 6)
                    number6_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1 == "6").Count();
            }

            return new List<int[]> {    new int[] { number1_Hang1, number2_Hang1, number3_Hang1, number4_Hang1, number5_Hang1, number6_Hang1}, 
                                        new int[] { number1_Hang2, number2_Hang2, number3_Hang2, number4_Hang2, number5_Hang2, number6_Hang2}, 
                                        new int[] { number1_Hang3, number2_Hang3, number3_Hang3, number4_Hang3, number5_Hang3, number6_Hang3}, 
                                        new int[] { number1_Hang4, number2_Hang4, number3_Hang4, number4_Hang4, number5_Hang4, number6_Hang4}, 
                                        new int[] { number1_Hang5, number2_Hang5, number3_Hang5, number4_Hang5, number5_Hang5, number6_Hang5}, 
                                        new int[] { number1_Hang6, number2_Hang6, number3_Hang6, number4_Hang6, number5_Hang6, number6_Hang6}, 
                                        new int[] { number1_Hang7, number2_Hang7, number3_Hang7, number4_Hang7, number5_Hang7, number6_Hang7}, 
                                        new int[] { number1_Hang8, number2_Hang8, number3_Hang8, number4_Hang8, number5_Hang8, number6_Hang8},
            };
        }
        public List<int[]> Dem2TieuChiCungMotPhieu_KieuContains(string loaiPhieu, int soHang, int soCot, int maCauHang, int maCauCot)
        {
            List<ChiTietPhieu> lsChiTietPhieuMaCauHang = (from ds in dataContext.Phieus
                                                          join ct in dataContext.ChiTietPhieus
                                                              on ds.ID equals ct.PhieuID
                                                          where ct.MaCau == maCauHang && ds.LoaiPhieu == loaiPhieu && ct.CauTraLoiFIX1 != ""
                                                          select ct).ToList();
            List<System.Guid> lsHang1ID = new List<Guid>();
            List<System.Guid> lsHang2ID = new List<Guid>();
            List<System.Guid> lsHang3ID = new List<Guid>();
            List<System.Guid> lsHang4ID = new List<Guid>();
            List<System.Guid> lsHang5ID = new List<Guid>();
            List<System.Guid> lsHang6ID = new List<Guid>();
            List<System.Guid> lsHang7ID = new List<Guid>();
            List<System.Guid> lsHang8ID = new List<Guid>();
            if (soHang >= 1)
                lsHang1ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "1" select ds.PhieuID).ToList();
            if (soHang >= 2)
                lsHang2ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "2" select ds.PhieuID).ToList();
            if (soHang >= 3)
                lsHang3ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "3" select ds.PhieuID).ToList();
            if (soHang >= 4)
                lsHang4ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "4" select ds.PhieuID).ToList();
            if (soHang >= 5)
                lsHang5ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "5" select ds.PhieuID).ToList();
            if (soHang >= 6)
                lsHang6ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "6" select ds.PhieuID).ToList();
            if (soHang >= 7)
                lsHang7ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "7" select ds.PhieuID).ToList();
            if (soHang >= 8)
                lsHang8ID = (from ds in lsChiTietPhieuMaCauHang where ds.CauTraLoiFIX1 == "8" select ds.PhieuID).ToList();


            List<ChiTietPhieu> lsChiTietPhieuMaCauCot = (from ds in dataContext.Phieus
                                                         join ct in dataContext.ChiTietPhieus
                                                             on ds.ID equals ct.PhieuID
                                                         where ct.MaCau == maCauCot && ds.LoaiPhieu == loaiPhieu && ct.CauTraLoiFIX1 != ""
                                                         select ct).ToList();
            //Tạo biến temp để developer xem số lượng câu query được
            int count = lsChiTietPhieuMaCauHang.Count;
            int count2 = lsChiTietPhieuMaCauCot.Count;

            int number1_Hang1 = 0, number2_Hang1 = 0, number3_Hang1 = 0, number4_Hang1 = 0, number5_Hang1 = 0, number6_Hang1 = 0;
            int number1_Hang2 = 0, number2_Hang2 = 0, number3_Hang2 = 0, number4_Hang2 = 0, number5_Hang2 = 0, number6_Hang2 = 0;
            int number1_Hang3 = 0, number2_Hang3 = 0, number3_Hang3 = 0, number4_Hang3 = 0, number5_Hang3 = 0, number6_Hang3 = 0;
            int number1_Hang4 = 0, number2_Hang4 = 0, number3_Hang4 = 0, number4_Hang4 = 0, number5_Hang4 = 0, number6_Hang4 = 0;
            int number1_Hang5 = 0, number2_Hang5 = 0, number3_Hang5 = 0, number4_Hang5 = 0, number5_Hang5 = 0, number6_Hang5 = 0;
            int number1_Hang6 = 0, number2_Hang6 = 0, number3_Hang6 = 0, number4_Hang6 = 0, number5_Hang6 = 0, number6_Hang6 = 0;
            int number1_Hang7 = 0, number2_Hang7 = 0, number3_Hang7 = 0, number4_Hang7 = 0, number5_Hang7 = 0, number6_Hang7 = 0;
            int number1_Hang8 = 0, number2_Hang8 = 0, number3_Hang8 = 0, number4_Hang8 = 0, number5_Hang8 = 0, number6_Hang8 = 0;

            if (lsHang1ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang1 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang2ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang2ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang2 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang3ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang3ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang3 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang4ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang4ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang4 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang5ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang5ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang5 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang6ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang6ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang6 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang7ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang7ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang7 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            if (lsHang8ID.Count > 0)
            {
                if (soCot >= 1)
                    number1_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("1")).Count();
                if (soCot >= 2)
                    number2_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("2")).Count();
                if (soCot >= 3)
                    number3_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("3")).Count();
                if (soCot >= 4)
                    number4_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang8ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("4")).Count();
                if (soCot >= 5)
                    number5_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("5")).Count();
                if (soCot >= 6)
                    number6_Hang8 = lsChiTietPhieuMaCauCot.Where(x => lsHang1ID.Contains(x.PhieuID) && x.CauTraLoiFIX1.Contains("6")).Count();
            }

            return new List<int[]> {    new int[] { number1_Hang1, number2_Hang1, number3_Hang1, number4_Hang1, number5_Hang1, number6_Hang1}, 
                                        new int[] { number1_Hang2, number2_Hang2, number3_Hang2, number4_Hang2, number5_Hang2, number6_Hang2}, 
                                        new int[] { number1_Hang3, number2_Hang3, number3_Hang3, number4_Hang3, number5_Hang3, number6_Hang3}, 
                                        new int[] { number1_Hang4, number2_Hang4, number3_Hang4, number4_Hang4, number5_Hang4, number6_Hang4}, 
                                        new int[] { number1_Hang5, number2_Hang5, number3_Hang5, number4_Hang5, number5_Hang5, number6_Hang5}, 
                                        new int[] { number1_Hang6, number2_Hang6, number3_Hang6, number4_Hang6, number5_Hang6, number6_Hang6}, 
                                        new int[] { number1_Hang7, number2_Hang7, number3_Hang7, number4_Hang7, number5_Hang7, number6_Hang7}, 
                                        new int[] { number1_Hang8, number2_Hang8, number3_Hang8, number4_Hang8, number5_Hang8, number6_Hang8},
            };
        }

        public int[] DemCauTraLoiTheoPhieu_Fix1_KieuEquals(string loaiPhieu, int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                                 select ct).ToList();
            int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "1").Count();
            int number2 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "2").Count();
            int number3 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "3").Count();
            int number4 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "4").Count();
            int number5 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "5").Count();
            int number6 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "6").Count();
            int number7 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "7").Count();
            int number8 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "8").Count();

            return new int[] { number1, number2, number3, number4, number5, number6, number7, number8, lsChiTietPhieu.Count };
        }
        public int[] DemCauTraLoiTheoPhieu_Fix2_KieuEquals(string loaiPhieu, int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                                 select ct).ToList();
            int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "1").Count();
            int number2 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "2").Count();
            int number3 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "3").Count();
            int number4 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "4").Count();
            int number5 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "5").Count();
            int number6 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "6").Count();
            int number7 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "7").Count();
            int number8 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "8").Count();

            return new int[] { number1, number2, number3, number4, number5, number6, number7, number8, lsChiTietPhieu.Count };
        }

        public int[] DemCauTraLoiTheoPhieu_Fix1_KieuContains(string loaiPhieu, int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                                 select ct).ToList();
            int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("1")).Count();
            int number2 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("2")).Count();
            int number3 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("3")).Count();
            int number4 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("4")).Count();
            int number5 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("5")).Count();
            int number6 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("6")).Count();
            int number7 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("7")).Count();
            int number8 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("8")).Count();

            return new int[] { number1, number2, number3, number4, number5, number6, number7, number8, lsChiTietPhieu.Count };
        }
        public int[] DemCauTraLoiTheoPhieu_Fix2_KieuContains(string loaiPhieu, int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                                 select ct).ToList();
            int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("1")).Count();
            int number2 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("2")).Count();
            int number3 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("3")).Count();
            int number4 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("4")).Count();
            int number5 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("5")).Count();
            int number6 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("6")).Count();
            int number7 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("7")).Count();
            int number8 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("8")).Count();

            return new int[] { number1, number2, number3, number4, number5, number6, number7, number8, lsChiTietPhieu.Count };
        }

        public int[] DemCauTraLoiTheoPhieu_Fix1_KieuEquals_NguoiTraLoiPV(string loaiPhieu, int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                                 select ct).ToList();
            int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "1").Count();
            int number2 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "2").Count();
            int number3 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "3").Count();
            int number4 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "4").Count();
            int number5 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "5").Count();
            int number6 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "6").Count();
            int number7 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "7").Count();
            int number8 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "8").Count();

            return new int[] { number1, number2, number3, number4, number5, number6, number7, number8 };
        }

        public Hashtable DemCauTraLoiTheoPhieu_Text1(string loaiPhieu, int maCau)
        {
            Hashtable hash = new Hashtable();

            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                                 select ct).ToList();


            var danhsachNghe = (from ds in dataContext.Phieus
                                join ct in dataContext.ChiTietPhieus
                                    on ds.ID equals ct.PhieuID
                                where ct.MaCau == maCau && ds.LoaiPhieu == loaiPhieu
                                select ct.CauTraLoiText1).Distinct();

            foreach (var item in danhsachNghe)
            {
                //Duyệt từng trả lời rồi đếm
                if (item.ToString().Trim() != "")
                {
                    int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiText1.Equals(item.ToString())).Count();
                    if (!hash.ContainsKey(item.ToString().Trim()))
                        hash.Add(item.ToString().Trim(), number1);
                    else
                        hash[item.ToString().Trim()] = number1;
                }
            }
            return hash;

            //return new int[] { number1, number2, number3, number4, number5, number6, number7, number8 };
        }

        public List<Phieu> GetListPhieuCFromByMien(string thanhThiOrNongThon)
        {
            //Quận --> thành thị, Huyện --> Nông thôn
            List<Phieu> lsPhieu = null;
            //if (thanhThiOrNongThon == "Quận")
            //    lsPhieu = (from a in dataContext.Phieus
            //               join b in dataContext.CoQuans on a.CoQuanID equals b.ID
            //               join c in dataContext.QuanHuyens on b.QuanHuyenID equals c.ID
            //               where (c.Ten.Contains("Quận") || c.Ten.Contains("Thị xã") || c.Ten.Contains("Thành phố"))
            //                    && a.LoaiPhieu == "PhieuA"
            //               select a).ToList();
            //else
            //    lsPhieu = (from a in dataContext.Phieus
            //               join b in dataContext.CoQuans on a.CoQuanID equals b.ID
            //               join c in dataContext.QuanHuyens on b.QuanHuyenID equals c.ID
            //               where c.Ten.Contains("Huyện") && a.LoaiPhieu == "PhieuA"
            //               select a).ToList();

            if (thanhThiOrNongThon == "Huyện")
                lsPhieu = (from a in dataContext.Phieus
                           join b in dataContext.CoQuans on a.CoQuanID equals b.ID
                           join c in dataContext.QuanHuyens on b.QuanHuyenID equals c.ID
                           where c.Ten.Contains("Huyện") && a.LoaiPhieu == "PhieuA"
                           select a).ToList();
            else
                lsPhieu = (from a in dataContext.Phieus
                           join b in dataContext.CoQuans on a.CoQuanID equals b.ID
                           join c in dataContext.QuanHuyens on b.QuanHuyenID equals c.ID
                           where !c.Ten.Contains("Huyện") && a.LoaiPhieu == "PhieuA"
                           select a).ToList();

            return lsPhieu;
        }
        public List<Phieu> GetListPhieuCByGioiTinh(bool gioiTinh)
        {
            List<Phieu> lsPhieu = (from a in dataContext.Phieus
                                   join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                                   where b.GioiTinh == gioiTinh && a.LoaiPhieu == "PhieuA"
                                   select a).ToList();
            return lsPhieu;
        }
        public List<Phieu> GetListPhieuCByDanTocKinh()
        {
            //Tuấn làm lưu dân tộc vào trường Chức vụ đối với phiếu C
            List<Phieu> lsPhieu = (from a in dataContext.Phieus
                                   join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                                   where b.ChucVu.ToUpper().Contains("KINH") && a.LoaiPhieu == "PhieuA"
                                   select a).ToList();
            return lsPhieu;
        }
        public List<Phieu> GetListPhieuCByDanTocKhac()
        {
            //Tuấn làm lưu dân tộc vào trường Chức vụ đối với phiếu C
            List<Phieu> lsPhieu = (from a in dataContext.Phieus
                                   join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                                   where (!b.ChucVu.ToUpper().Contains("KINH")) && a.LoaiPhieu == "PhieuA"
                                   select a).ToList();
            return lsPhieu;
        }
        public List<Phieu> GetListPhieuCByDoTuoi(int min, int max)
        {
            List<Phieu> lsPhieu = (from a in dataContext.Phieus
                                   join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                                   where a.LoaiPhieu == "PhieuA" && (min <= b.Tuoi && b.Tuoi <= max)
                                   select a).ToList();
            return lsPhieu;
        }
        public int[] GetListPhieuCByDoTuoiAndGioiTinh(int min, int max)
        {
            int nam = (from a in dataContext.Phieus
                       join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                       where a.LoaiPhieu == "PhieuA" && (min <= b.Tuoi && b.Tuoi <= max) && b.GioiTinh == true
                       select a).ToList().Count;

            int nu = (from a in dataContext.Phieus
                      join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                      where a.LoaiPhieu == "PhieuA" && (min <= b.Tuoi && b.Tuoi <= max) && b.GioiTinh == false
                      select a).ToList().Count;

            int total = GetListPhieuCByDoTuoi(min, max).Count;

            return new int[] { nam, nu, total };
        }

        public string GetCauTraLoiFix1_ByPhieuIDAndMaCau(Guid phieuID, int maCau)
        {
            string str = (from a in dataContext.Phieus
                          join b in dataContext.ChiTietPhieus on a.ID equals b.PhieuID
                          where a.ID == phieuID && b.MaCau == maCau
                          select b.CauTraLoiFIX1).First().ToString();
            return str;
        }

        public List<NguoiTraLoiPV> GetListNguoiTraLoiPVPhieuCByGioiTinh(bool gioiTinh)
        {
            List<NguoiTraLoiPV> lsNguoiTraLoiPV = (from a in dataContext.Phieus
                                                   join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                                                   where b.GioiTinh == gioiTinh && a.LoaiPhieu == "PhieuA"
                                                   select b).ToList();
            return lsNguoiTraLoiPV;
        }
        public List<NguoiTraLoiPV> GetListNguoiTraLoiPVPhieuCByDoTuoi(int min, int max)
        {
            List<NguoiTraLoiPV> lsNguoiTraLoiPV = (from a in dataContext.Phieus
                                                   join b in dataContext.NguoiTraLoiPVs on a.NguoiTraLoiPVID equals b.ID
                                                   where a.LoaiPhieu == "PhieuA" && (min <= b.Tuoi && b.Tuoi <= max)
                                                   select b).ToList();
            return lsNguoiTraLoiPV;
        }


        //Phiếu B
        private List<Phieu_DangBang> getListPhieuDangBang_PhieuB(int maCau)
        {
            //danh sach cau tra loi o day
            return (from ds in dataContext.Phieus
                    join ct in dataContext.Phieu_DangBangs
                        on ds.ID equals ct.PhieuID
                    where ct.MaCau == maCau && ds.LoaiPhieu == "PhieuB"
                    select ct).ToList();
        }

        public double[] GetCauTraLoiText_1_2_PhieuB(int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == "PhieuB"
                                                 select ct).ToList();

            double number1 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText1));
            double number2 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText2));
            return new double[] { number1, number2 };
        }

        public double[] GetCauTraLoiText_1_2_3_PhieuB(int maCau)
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == maCau && ds.LoaiPhieu == "PhieuB"
                                                 select ct).ToList();

            double number1 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText1));
            double number2 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText2));
            double number3 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText3));
            return new double[] { number1, number2, number3 };
        }

        public List<int[]> GetDataSUM3Hang3Cot(int maCau)
        {
            List<Phieu_DangBang> lsChiTietPhieu = getListPhieuDangBang_PhieuB(maCau);

            int[] arrayThuTuTrongBang = new int[] { 0, 1, 2 };  //Lấy ThuTuTrongBang 012
            List<int[]> result = new List<int[]>();

            for (int i = 0; i < arrayThuTuTrongBang.Count(); i++)
            {
                int number1 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number1).Average();
                int number2 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number2).Average();
                int number3 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number3).Average();
                result.Add(new int[] { number1, number2, number3 });
            }
            return result;
        }

        public List<double[]> GetDataSUM3Hang6Cot(int maCau)
        {
            List<Phieu_DangBang> lsChiTietPhieu = getListPhieuDangBang_PhieuB(maCau);

            double[] arrayThuTuTrongBang = new double[] { 0, 1, 2 };  //Lấy ThuTuTrongBang 012
            List<double[]> result = new List<double[]>();

            for (int i = 0; i < arrayThuTuTrongBang.Count(); i++)
            {
                double number1 = (double)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number1).Sum();
                double number2 = (double)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number2).Sum();
                double number3 = (double)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number3).Sum();
                double number4 = (double)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number4).Sum();
                double number5 = (double)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number5).Sum();
                double number6 = (double)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number6).Sum();
                result.Add(new double[] { number1, number2, number3, number4, number5, number6 });
            }
            return result;
        }

        public List<int[]> GetDataSUM3Hang4Cot(int maCau)
        {
            List<Phieu_DangBang> lsChiTietPhieu = getListPhieuDangBang_PhieuB(maCau);

            int[] arrayThuTuTrongBang = new int[] { 0, 1, 2 };  //Lấy ThuTuTrongBang 012
            List<int[]> result = new List<int[]>();

            for (int i = 0; i < arrayThuTuTrongBang.Count(); i++)
            {
                int number1 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number1).Sum();
                int number2 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number2).Sum();
                int number3 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number3).Sum();
                int number4 = (int)lsChiTietPhieu.Where(x => x.ThuTuTrongBang == arrayThuTuTrongBang[i]).Select(c => c.Number4).Sum();
                result.Add(new int[] { number1, number2, number3, number4 });
            }
            return result;
        }

        public List<double[]> GetDataB11()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == 20 && ds.LoaiPhieu == "PhieuB"
                                                 select ct).ToList();

            List<double[]> result = new List<double[]>();

            //fix1
            double number11 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "1").Count();
            double number21 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1 == "2").Count();
            double sum = (number11 + number21);
            double number12 = number11 / sum;
            double number22 = number21 / sum;
            result.Add(new double[] { number11, number12 });
            result.Add(new double[] { number21, number22 });

            //fix2
            double number31 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "1").Count();
            double number41 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "2").Count();
            double number51 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX2 == "3").Count();
            sum = number31 + number41 + number51;
            double number32 = number31 / sum;
            double number42 = number41 / sum;
            double number52 = number51 / sum;
            result.Add(new double[] { number31, number32 });
            result.Add(new double[] { number41, number42 });
            result.Add(new double[] { number51, number52 });

            //fix3
            double number61 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX3 == "1").Count();
            double number71 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX3 == "2").Count();
            sum = (number61 + number71);
            double number62 = number61 / sum;
            double number72 = number71 / sum;
            result.Add(new double[] { number61, number72 });
            result.Add(new double[] { number71, number72 });

            //fix4
            double number81 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX4 == "1").Count();
            double number91 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX4 == "2").Count();
            sum = (number81 + number91);
            double number82 = number81 / sum;
            double number92 = number91 / sum;
            result.Add(new double[] { number81, number82 });
            result.Add(new double[] { number91, number92 });

            //fix5
            double number101 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX5 == "1").Count();
            double number111 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX5 == "2").Count();
            sum = (number101 + number111);
            double number102 = number101 / sum;
            double number112 = number111 / sum;
            result.Add(new double[] { number101, number102 });
            result.Add(new double[] { number111, number112 });

            //fix6
            double number121 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX6 == "1").Count();
            double number131 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX6 == "2").Count();
            sum = (number121 + number131);
            double number122 = number121 / sum;
            double number132 = number131 / sum;
            result.Add(new double[] { number121, number122 });
            result.Add(new double[] { number131, number132 });

            //fix7
            double number141 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX7 == "1").Count();
            double number151 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX7 == "2").Count();
            sum = (number141 + number151);
            double number142 = number141 / sum;
            double number152 = number151 / sum;
            result.Add(new double[] { number141, number142 });
            result.Add(new double[] { number151, number152 });

            //fix4
            double number161 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX8 == "1").Count();
            double number171 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX8 == "2").Count();
            sum = (number161 + number171);
            double number162 = number161 / sum;
            double number172 = number171 / sum;
            result.Add(new double[] { number161, number162 });
            result.Add(new double[] { number171, number172 });

            return result;
        }

        //Phiếu A
        public int[] GetDataC0()
        {
            int number1 = GetListPhieuCFromByMien("Quận").Count;
            int number2 = GetListPhieuCFromByMien("Huyện").Count;
            return new int[] { number1, number2 };
        }

        //Method tính mức độ hiểu biết nằm ở NguoiTraLoiPVRepository --> điểm tính ra lưu vào NamLamViec
        public int[] GetDataC8()
        {
            NguoiTraLoiPVRepository temp = new NguoiTraLoiPVRepository();
            temp.MucDoHieuBietByNguoiTraLoiPhongVan();

            int hieuDayDu = (from a in dataContext.NguoiTraLoiPVs
                             where 80 <= Convert.ToInt32(a.NamLamViec)
                             select a).Count();
            int coBiet = (from a in dataContext.NguoiTraLoiPVs
                          where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                          select a).Count();
            int khongBiet = (from a in dataContext.NguoiTraLoiPVs
                             where Convert.ToInt32(a.NamLamViec) < 20
                             select a).Count();
            return new int[] { hieuDayDu, coBiet, khongBiet };
        }

        public List<int[]> GetDataC9()
        {
            List<NguoiTraLoiPV> lstNam = GetListNguoiTraLoiPVPhieuCByGioiTinh(true);
            List<NguoiTraLoiPV> lstNu = GetListNguoiTraLoiPVPhieuCByGioiTinh(false);
            List<int[]> result = new List<int[]>();

            int namHieuDayDu = (from a in lstNam
                                where 80 <= Convert.ToInt32(a.NamLamViec)
                                select a).Count();
            int namcoBiet = (from a in lstNam
                             where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                             select a).Count();
            int namkhongBiet = (from a in lstNam
                                where Convert.ToInt32(a.NamLamViec) < 20
                                select a).Count();
            int[] temp = new int[] { namHieuDayDu, namcoBiet, namkhongBiet };
            result.Add(temp);

            int nuHieuDayDu = (from a in lstNu
                               where 80 <= Convert.ToInt32(a.NamLamViec)
                               select a).Count();
            int nucoBiet = (from a in lstNu
                            where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                            select a).Count();
            int nukhongBiet = (from a in lstNu
                               where Convert.ToInt32(a.NamLamViec) < 20
                               select a).Count();
            temp = new int[] { nuHieuDayDu, nucoBiet, nukhongBiet };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC10()
        {
            List<NguoiTraLoiPV> lst_15_29 = GetListNguoiTraLoiPVPhieuCByDoTuoi(15, 29);
            List<NguoiTraLoiPV> lst_30_39 = GetListNguoiTraLoiPVPhieuCByDoTuoi(30, 39);
            List<NguoiTraLoiPV> lst_40_49 = GetListNguoiTraLoiPVPhieuCByDoTuoi(40, 49);
            List<NguoiTraLoiPV> lst_50_59 = GetListNguoiTraLoiPVPhieuCByDoTuoi(50, 59);
            List<int[]> result = new List<int[]>();

            int hieuDayDu1 = (from a in lst_15_29
                              where 80 <= Convert.ToInt32(a.NamLamViec)
                              select a).Count();
            int coBiet1 = (from a in lst_15_29
                           where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                           select a).Count();
            int khongBiet1 = (from a in lst_15_29
                              where Convert.ToInt32(a.NamLamViec) < 20
                              select a).Count();
            int[] temp = new int[] { hieuDayDu1, coBiet1, khongBiet1 };
            result.Add(temp);

            hieuDayDu1 = (from a in lst_30_39
                          where 80 <= Convert.ToInt32(a.NamLamViec)
                          select a).Count();
            coBiet1 = (from a in lst_30_39
                       where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                       select a).Count();
            khongBiet1 = (from a in lst_30_39
                          where Convert.ToInt32(a.NamLamViec) < 20
                          select a).Count();
            temp = new int[] { hieuDayDu1, coBiet1, khongBiet1 };
            result.Add(temp);

            hieuDayDu1 = (from a in lst_40_49
                          where 80 <= Convert.ToInt32(a.NamLamViec)
                          select a).Count();
            coBiet1 = (from a in lst_40_49
                       where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                       select a).Count();
            khongBiet1 = (from a in lst_40_49
                          where Convert.ToInt32(a.NamLamViec) < 20
                          select a).Count();
            temp = new int[] { hieuDayDu1, coBiet1, khongBiet1 };
            result.Add(temp);

            hieuDayDu1 = (from a in lst_50_59
                          where 80 <= Convert.ToInt32(a.NamLamViec)
                          select a).Count();
            coBiet1 = (from a in lst_50_59
                       where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                       select a).Count();
            khongBiet1 = (from a in lst_50_59
                          where Convert.ToInt32(a.NamLamViec) < 20
                          select a).Count();
            temp = new int[] { hieuDayDu1, coBiet1, khongBiet1 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC11()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == 7 && ds.LoaiPhieu == "PhieuA"
                                                 select ct).ToList();
            //lấy ra PhieuID của các câu trả lời trong MaCau = 7
            List<Guid> phieuID1 = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "1" select a.PhieuID).ToList();
            List<Guid> phieuID2 = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "2" select a.PhieuID).ToList();
            List<Guid> phieuID3 = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "3" select a.PhieuID).ToList();
            List<Guid> phieuID4 = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "4" select a.PhieuID).ToList();
            List<Guid> phieuID5 = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "5" select a.PhieuID).ToList();

            //Lọc từng phiếu ID với HieuBiet của NguoiTraLoiPV
            List<Phieu> lshieuDayDu = (from a in dataContext.NguoiTraLoiPVs
                                       join b in dataContext.Phieus on a.ID equals b.NguoiTraLoiPVID
                                       where 80 <= Convert.ToInt32(a.NamLamViec)
                                       select b).ToList();
            List<Phieu> lscoBiet = (from a in dataContext.NguoiTraLoiPVs
                                    join b in dataContext.Phieus on a.ID equals b.NguoiTraLoiPVID
                                    where 20 <= Convert.ToInt32(a.NamLamViec) && Convert.ToInt32(a.NamLamViec) < 80
                                    select b).ToList();

            List<Phieu> lskhongBiet = (from a in dataContext.NguoiTraLoiPVs
                                       join b in dataContext.Phieus on a.ID equals b.NguoiTraLoiPVID
                                       where Convert.ToInt32(a.NamLamViec) < 20
                                       select b).ToList();

            int cot11 = lshieuDayDu.Where(x => phieuID1.Contains(x.ID)).Count();
            int cot12 = lshieuDayDu.Where(x => phieuID2.Contains(x.ID)).Count();
            int cot13 = lshieuDayDu.Where(x => phieuID3.Contains(x.ID)).Count();
            int cot14 = lshieuDayDu.Where(x => phieuID4.Contains(x.ID)).Count();
            int cot15 = lshieuDayDu.Where(x => phieuID5.Contains(x.ID)).Count();

            int cot21 = lscoBiet.Where(x => phieuID1.Contains(x.ID)).Count();
            int cot22 = lscoBiet.Where(x => phieuID2.Contains(x.ID)).Count();
            int cot23 = lscoBiet.Where(x => phieuID3.Contains(x.ID)).Count();
            int cot24 = lscoBiet.Where(x => phieuID4.Contains(x.ID)).Count();
            int cot25 = lscoBiet.Where(x => phieuID5.Contains(x.ID)).Count();

            int cot31 = lskhongBiet.Where(x => phieuID1.Contains(x.ID)).Count();
            int cot32 = lskhongBiet.Where(x => phieuID2.Contains(x.ID)).Count();
            int cot33 = lskhongBiet.Where(x => phieuID3.Contains(x.ID)).Count();
            int cot34 = lskhongBiet.Where(x => phieuID4.Contains(x.ID)).Count();
            int cot35 = lskhongBiet.Where(x => phieuID5.Contains(x.ID)).Count();

            return new List<int[]> {    new int[] { cot11, cot21, cot31},
                                        new int[] { cot12, cot22, cot32}, 
                                        new int[] { cot13, cot23, cot33}, 
                                        new int[] { cot14, cot24, cot34}, 
                                        new int[] { cot15, cot25, cot35}, 
            };
        }

        public List<int[]> GetDataC12()
        {
            List<int[]> result = Dem2TieuChiCungMotPhieu_KieuContains("PhieuA", 5, 5, 7, 18);
            return result;
        }
        public List<int[]> GetDataC13()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == 19 && ds.LoaiPhieu == "PhieuA"
                                                 select ct).ToList();
            //lấy ra PhieuID của các câu trả lời trong MaCau = 7
            List<Guid> phieuID_TraLoiChua = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "1" select a.PhieuID).ToList();
            List<Guid> phieuID_TraLoiDa = (from a in lsChiTietPhieu where a.CauTraLoiFIX1 == "2" select a.PhieuID).ToList();

            //Lọc từng phiếu ID với HieuBiet của NguoiTraLoiPV
            List<Phieu> lsNam = GetListPhieuCByGioiTinh(true);
            List<Phieu> lsNu = GetListPhieuCByGioiTinh(false);

            int cot11 = lsNam.Where(x => phieuID_TraLoiChua.Contains(x.ID)).Count();
            int cot12 = lsNam.Where(x => phieuID_TraLoiDa.Contains(x.ID)).Count();

            int cot21 = lsNu.Where(x => phieuID_TraLoiChua.Contains(x.ID)).Count();
            int cot22 = lsNu.Where(x => phieuID_TraLoiDa.Contains(x.ID)).Count();

            return new List<int[]> {    new int[] { cot11, cot21},
                                        new int[] { cot12, cot22}, 
            };
        }

        public double[] GetDataC15()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from a in dataContext.Phieus
                                                 join b in dataContext.ChiTietPhieus on a.ID equals b.PhieuID
                                                 where a.LoaiPhieu == "PhieuA" && b.MaCau == 21 && b.CauTraLoiText1 != ""
                                                 select b).ToList();
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận").ToList();
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện").ToList();
            List<Guid> phieuIDThanhThi = (from a in lsThanhThi select a.ID).ToList();
            List<Guid> phieuIDNongThon = (from a in lsNongThon select a.ID).ToList();

            double sumThanhThi = lsChiTietPhieu.Where(x => phieuIDThanhThi.Contains(x.PhieuID)).Sum(y => Convert.ToDouble(y.CauTraLoiText1));
            double sumTNongThon = lsChiTietPhieu.Where(x => phieuIDNongThon.Contains(x.PhieuID)).Sum(y => Convert.ToDouble(y.CauTraLoiText1));
            double cot1 = sumThanhThi / phieuIDThanhThi.Count;
            double cot2 = sumTNongThon / phieuIDNongThon.Count;
            double cot3 = (sumThanhThi + sumTNongThon) / (phieuIDThanhThi.Count + phieuIDNongThon.Count);

            return new double[] { cot1, cot2, cot3 };
        }

        //Câu này đặc biệt có 14 câu trả lời
        public double[] GetDataC16()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == 22 && ds.LoaiPhieu == "PhieuA"
                                                 select ct).ToList();
            int number1 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("1")).Count();
            int number2 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("2")).Count();
            int number3 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("3")).Count();
            int number4 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("4")).Count();
            int number5 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("5")).Count();
            int number6 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("6")).Count();
            int number7 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("7")).Count();
            int number8 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("8")).Count();
            int number9 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("9")).Count();
            int number10 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("10")).Count();
            int number11 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("11")).Count();
            int number12 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("12")).Count();
            int number13 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("13")).Count();
            int number14 = lsChiTietPhieu.Where(x => x.CauTraLoiFIX1.Contains("14")).Count();

            return new double[] { number1, number2, number3, number4, number5, number6, number7, 
                number8, number9, number10, number11, number12, number13, number14, lsChiTietPhieu.Count};
        }

        public double[] GetDataC17()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == 23 && ds.LoaiPhieu == "PhieuA"
                                                 select ct).ToList();
            double number1 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText1));
            double number2 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText2));
            double number3 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText3));
            double number4 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText4));
            double number5 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText5));
            double number6 = lsChiTietPhieu.Sum(x => Convert.ToDouble(x.CauTraLoiText6));

            double sum = number1 + number2 + number3 + number4 + number5 + number6;

            return new double[] { number1, number2, number3, number4, number5, number6, sum };
        }

        public List<double[]> GetDataC18()
        {

            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");

            List<ChiTietPhieu> lsChiTietPhieuThanhThi = (from ds in lsThanhThi
                                                         join ct in dataContext.ChiTietPhieus
                                                             on ds.ID equals ct.PhieuID
                                                         where ct.MaCau == 23 && ds.LoaiPhieu == "PhieuA"
                                                         select ct).ToList();

            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            List<ChiTietPhieu> lsChiTietPhieuNongThon = (from ds in lsNongThon
                                                         join ct in dataContext.ChiTietPhieus
                                                             on ds.ID equals ct.PhieuID
                                                         where ct.MaCau == 23 && ds.LoaiPhieu == "PhieuA"
                                                         select ct).ToList();


            //Thành thị
            double number11 = lsChiTietPhieuThanhThi.Where(x => (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 1000000).Count();

            double number12 = lsChiTietPhieuThanhThi.Where(x => (1000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 2000000)).Count();

            double number13 = lsChiTietPhieuThanhThi.Where(x => (2000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 3000000)).Count();

            double number14 = lsChiTietPhieuThanhThi.Where(x => (3000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 4000000)).Count();

            double number15 = lsChiTietPhieuThanhThi.Where(x => (4000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
               + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
               (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
               + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 5000000)).Count();

            double number16 = lsChiTietPhieuThanhThi.Where(x => (5000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
              + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)))).Count();

            //Nông thôn
            double number21 = lsChiTietPhieuNongThon.Where(x => (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
              + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 1000000).Count();

            double number22 = lsChiTietPhieuNongThon.Where(x => (1000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 2000000)).Count();

            double number23 = lsChiTietPhieuNongThon.Where(x => (2000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 3000000)).Count();

            double number24 = lsChiTietPhieuNongThon.Where(x => (3000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 4000000)).Count();

            double number25 = lsChiTietPhieuNongThon.Where(x => (4000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
               + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
               (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
               + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 5000000)).Count();

            double number26 = lsChiTietPhieuNongThon.Where(x => (5000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
              + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)))).Count();

            List<double[]> result = new List<double[]>();
            result.Add(new double[] { number11, number12, number13, number14, number15, number16 });
            result.Add(new double[] { number21, number22, number23, number24, number25, number26 });
            return result;
        }

        public double[] GetDataC19()
        {
            List<ChiTietPhieu> lsChiTietPhieu = (from ds in dataContext.Phieus
                                                 join ct in dataContext.ChiTietPhieus
                                                     on ds.ID equals ct.PhieuID
                                                 where ct.MaCau == 24 && ds.LoaiPhieu == "PhieuA"
                                                 select ct).ToList();
            double number1 = lsChiTietPhieu.Where(x => x.CauTraLoiText1 != "" && x.CauTraLoiText1 != "0").Count();
            double number2 = lsChiTietPhieu.Where(x => x.CauTraLoiText2 != "" && x.CauTraLoiText2 != "0").Count();
            double number3 = lsChiTietPhieu.Where(x => x.CauTraLoiText3 != "" && x.CauTraLoiText3 != "0").Count();
            double number4 = lsChiTietPhieu.Where(x => x.CauTraLoiText4 != "" && x.CauTraLoiText4 != "0").Count();
            double number5 = lsChiTietPhieu.Where(x => x.CauTraLoiText5 != "" && x.CauTraLoiText5 != "0").Count();
            double number6 = lsChiTietPhieu.Where(x => x.CauTraLoiText6 != "" && x.CauTraLoiText6 != "0").Count();
            double number7 = lsChiTietPhieu.Where(x => x.CauTraLoiText7 != "" && x.CauTraLoiText7 != "0").Count();

            double sum = number1 + number2 + number3 + number4 + number5 + number6 + number7;

            return new double[] { number1, number2, number3, number4, number5, number6, number7, lsChiTietPhieu.Count };
        }

        public double[] GetDataC20()
        {
            List<ChiTietPhieu> lsChiTietPhieuThanhThi = (from ds in dataContext.Phieus
                                                         join ct in dataContext.ChiTietPhieus
                                                             on ds.ID equals ct.PhieuID
                                                         where ct.MaCau == 23 && ds.LoaiPhieu == "PhieuA"
                                                         select ct).ToList();

            double number11 = lsChiTietPhieuThanhThi.Where(x => (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 1000000).Count();

            double number12 = lsChiTietPhieuThanhThi.Where(x => (1000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 2000000)).Count();

            double number13 = lsChiTietPhieuThanhThi.Where(x => (2000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 3000000)).Count();

            double number14 = lsChiTietPhieuThanhThi.Where(x => (3000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
                (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
                + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 4000000)).Count();

            double number15 = lsChiTietPhieuThanhThi.Where(x => (4000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
               + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) &&
               (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
               + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)) < 5000000)).Count();

            double number16 = lsChiTietPhieuThanhThi.Where(x => (5000000 <= (Convert.ToDouble(x.CauTraLoiText1) + Convert.ToDouble(x.CauTraLoiText2) + Convert.ToDouble(x.CauTraLoiText3)
              + Convert.ToDouble(x.CauTraLoiText4) + Convert.ToDouble(x.CauTraLoiText5) + Convert.ToDouble(x.CauTraLoiText6)))).Count();

            return new double[] { number11, number12, number13, number14, number15, number16, lsChiTietPhieuThanhThi.Count };
        }

        public List<int[]> GetDataC23()
        {
            List<NguoiTraLoiPV> lstNam = GetListNguoiTraLoiPVPhieuCByGioiTinh(true);
            List<NguoiTraLoiPV> lstNu = GetListNguoiTraLoiPVPhieuCByGioiTinh(false);

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 27 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuNguoiTraLoiID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.Phieu.NguoiTraLoiPVID).ToList();
            List<Guid> lstPhieuNguoiTraLoiID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.Phieu.NguoiTraLoiPVID).ToList();

            List<int[]> result = new List<int[]>();

            int namCo = lstNam.Where(x => lstPhieuNguoiTraLoiID1.Contains(x.ID)).Count();
            int namKhong = lstNam.Where(x => lstPhieuNguoiTraLoiID2.Contains(x.ID)).Count();

            int[] temp = new int[] { namCo, namKhong };
            result.Add(temp);

            int nuCo = lstNu.Where(x => lstPhieuNguoiTraLoiID1.Contains(x.ID)).Count();
            int nuKhong = lstNu.Where(x => lstPhieuNguoiTraLoiID2.Contains(x.ID)).Count();

            temp = new int[] { nuCo, nuKhong };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC24()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 27 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int namCo = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int namKhong = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            int[] temp = new int[] { namCo, namKhong };
            result.Add(temp);

            int nuCo = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int nuKhong = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            temp = new int[] { nuCo, nuKhong };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC27()
        {
            List<NguoiTraLoiPV> lstNam = GetListNguoiTraLoiPVPhieuCByGioiTinh(true);
            List<NguoiTraLoiPV> lstNu = GetListNguoiTraLoiPVPhieuCByGioiTinh(false);

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 30 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuNguoiTraLoiID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.Phieu.NguoiTraLoiPVID).ToList();
            List<Guid> lstPhieuNguoiTraLoiID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.Phieu.NguoiTraLoiPVID).ToList();

            List<int[]> result = new List<int[]>();

            int namCo = lstNam.Where(x => lstPhieuNguoiTraLoiID1.Contains(x.ID)).Count();
            int namKhong = lstNam.Where(x => lstPhieuNguoiTraLoiID2.Contains(x.ID)).Count();

            int[] temp = new int[] { namCo, namKhong };
            result.Add(temp);

            int nuCo = lstNu.Where(x => lstPhieuNguoiTraLoiID1.Contains(x.ID)).Count();
            int nuKhong = lstNu.Where(x => lstPhieuNguoiTraLoiID2.Contains(x.ID)).Count();

            temp = new int[] { nuCo, nuKhong };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC28()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 30 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int namCo = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int namKhong = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            int[] temp = new int[] { namCo, namKhong };
            result.Add(temp);

            int nuCo = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int nuKhong = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            temp = new int[] { nuCo, nuKhong };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC29()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 31 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int namCo = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int namKhong = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            int[] temp = new int[] { namCo, namKhong };
            result.Add(temp);

            int nuCo = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int nuKhong = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            temp = new int[] { nuCo, nuKhong };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC30()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 32 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int namCo = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int namKhong = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            int[] temp = new int[] { namCo, namKhong };
            result.Add(temp);

            int nuCo = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int nuKhong = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            temp = new int[] { nuCo, nuKhong };
            result.Add(temp);

            return result;
        }

        //List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("4") select ds.PhieuID).ToList();
        public List<int[]> GetDataC31()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 33 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("3") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("4") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number41 = lsThanhThi.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31, number41 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number42 = lsNongThon.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32, number22 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC33()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 34 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("3") select ds.PhieuID).ToList();
            //List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("4") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC34()
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 35 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("3") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC35() //36a tức là maCau = 36 và trả lời Fix1
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 36 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("3") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX1.Equals("4") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number41 = lsThanhThi.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31, number41 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number42 = lsNongThon.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32, number22 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC36() //36b tức là maCau = 36 và trả lời Fix2
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 36 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX2.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX2.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX2.Equals("3") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX2.Equals("4") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number41 = lsThanhThi.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31, number41 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number42 = lsNongThon.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32, number42 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC37() //36c tức là maCau = 36 và trả lời Fix3456 và text3. Đếm tức là chỉ cần != "" là đếm
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 36 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();

            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX3 != "" select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX4 != "" select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX5 != "" select ds.PhieuID).ToList();
            List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX6 != "" select ds.PhieuID).ToList();
            List<Guid> lstPhieuID5 = (from ds in lstChiTietPhieu where ds.CauTraLoiText3 != "" select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number41 = lsThanhThi.Where(x => lstPhieuID4.Contains(x.ID)).Count();
            int number51 = lsThanhThi.Where(x => lstPhieuID5.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31, number41, number51, lsThanhThi.Count };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number42 = lsNongThon.Where(x => lstPhieuID4.Contains(x.ID)).Count();
            int number52 = lsNongThon.Where(x => lstPhieuID5.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32, number42, number52, lsNongThon.Count };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC38() //36d tức là maCau = 36 và trả lời Fix7
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 36 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX7.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX7.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX7.Equals("3") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX7.Equals("4") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number41 = lsThanhThi.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31, number41 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number42 = lsNongThon.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32, number22 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC39() //36đ tức là maCau = 36 và trả lời Fix8
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 36 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX8.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX8.Equals("2") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID3 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX8.Equals("3") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID4 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX8.Equals("4") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number31 = lsThanhThi.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number41 = lsThanhThi.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21, number31, number41 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();
            int number32 = lsNongThon.Where(x => lstPhieuID3.Contains(x.ID)).Count();
            int number42 = lsNongThon.Where(x => lstPhieuID4.Contains(x.ID)).Count();

            temp = new int[] { number12, number22, number32, number22 };
            result.Add(temp);

            return result;
        }

        public List<int[]> GetDataC40() //36e tức là maCau = 36 và trả lời Fix9
        {
            List<Phieu> lsThanhThi = GetListPhieuCFromByMien("Quận");
            List<Phieu> lsNongThon = GetListPhieuCFromByMien("Huyện");

            var lstChiTietPhieu = (from ds in dataContext.Phieus
                                   join ct in dataContext.ChiTietPhieus
                                       on ds.ID equals ct.PhieuID
                                   where ct.MaCau == 36 && ds.LoaiPhieu == "PhieuA"
                                   select ct).ToList();
            List<Guid> lstPhieuID1 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX9.Equals("1") select ds.PhieuID).ToList();
            List<Guid> lstPhieuID2 = (from ds in lstChiTietPhieu where ds.CauTraLoiFIX9.Equals("2") select ds.PhieuID).ToList();

            List<int[]> result = new List<int[]>();

            int number11 = lsThanhThi.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number21 = lsThanhThi.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            int[] temp = new int[] { number11, number21 };
            result.Add(temp);

            int number12 = lsNongThon.Where(x => lstPhieuID1.Contains(x.ID)).Count();
            int number22 = lsNongThon.Where(x => lstPhieuID2.Contains(x.ID)).Count();

            temp = new int[] { number12, number22 };
            result.Add(temp);

            return result;
        }

        const string HUYEN = "Huyện";
    }
}